﻿using ChenShiBao.AnyDBConfigProvider;
using System;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;


namespace Test
{
    public class Program
    {
        static void Main(string[] args)
        {
            ConfigurationBuilder configBuilder = new ConfigurationBuilder();
            // 设置基础路径并添加 appsettings.json 文件
            configBuilder.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
            // 构建配置
            var configFile = configBuilder.Build();
            // 读取连接字符串
            string connStr = configFile["DbSettings:ConnectionString"];
            //add the DbConfiguration to configBuilder
            configBuilder.AddDbConfiguration(() =>new MySqlConnection(connStr));
            var config = configBuilder.Build();

            var appItems = config.GetSection("Api:AppItems").Get<ApplicationItem[]>();
            //read configuration 
            string[] strs = config.GetSection("Cors:Origins").Get<string[]>();
            Console.WriteLine(string.Join("|", strs.Where(s => s != null)));
            var jwt = config.GetSection("Api:Jwt").Get<JWT>();
            Console.WriteLine(jwt.Secret);
            Console.WriteLine(jwt.Audience);
            Console.WriteLine(string.Join(",", jwt.Ids));
            Console.WriteLine(config["Age"]);

            Console.ReadKey();
        }
    }
}
